<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Đặng Khánh Trung
 * Date: 11/16/12
 * Time: 4:28 PM
 * To change this template use File | Settings | File Templates.
 */

defined('_JEXEC') or die;

class VastViewHosocanbotheophong extends JViewLegacy
{
    protected $form;
    protected $item;
    protected $state;
    protected $canDo;
    /**
     * Display the view
     */
    public function display($tpl = null)
    {
        // Initialiase variables.
        $this->form		= $this->get('Form');
        $this->item		= $this->get('Item');
        $this->state	= $this->get('State');

        JLoader::register('HosocanbosHelper', JPATH_COMPONENT . '/helpers/hosocanbo.php');
        $this->canDo	= HosocanbosHelper::getActions();

        // Check for errors.
        if (count($errors = $this->get('Errors'))) {
            JError::raiseError(500, implode("\n", $errors));
            return false;
        }

        $this->addToolbar();
        parent::display($tpl);
    }

    /**
     * Add the page title and toolbar.
     *
     * @since	1.6
     */
    protected function addToolbar()
    {
        JRequest::setVar('hidemainmenu', true);
        $isNew		= ($this->item->id == 0);
        $id = (int)JFactory::getApplication()->getUserState('phong_id');
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

        $query->select('a.*');
        $query->from('#__phong AS a');
        $query->where('a.id = ' . $id);

        $db->setQuery($query);
        $column = $db->loadObjectList();

        if (count($column) > 0)
            JToolBarHelper::title(JText::_('COM_VAST_HOSOCANBOTHEOPHONG_DETAIL') . ' ' . $column[0]->ten, 'head vm_manufacturer_48');
        else
            JToolBarHelper::title(JText::_('COM_VAST_HOSOCANBO_DETAIL'), 'head vm_manufacturer_48');
        JToolBarHelper::divider();

        if ($this->canDo->get('vast.phong.quanlyhosocanbo')) {
            JToolBarHelper::save2new('hosocanbotheophong.save2new', 'COM_VAST_HOSOCANBO_JTOOLBAR_SAVE2NEW');
            JToolBarHelper::save2copy('hosocanbotheophong.save2copy', 'COM_VAST_HOSOCANBO_JTOOLBAR_SAVE2COPY');
            JToolBarHelper::save('hosocanbotheophong.save', 'COM_VAST_HOSOCANBO_JTOOLBAR_SAVE');            
        }
        JToolBarHelper::cancel('hosocanbotheophong.cancel', $isNew ? 'COM_VAST_HOSOCANBO_JTOOLBAR_CANCEL' : 'COM_VAST_HOSOCANBO_JTOOLBAR_CLOSE');
    }
}